#https://pypi.tuna.tsinghua.edu.cn/simple 清华镜像源
#https://beijing.anjuke.com/sale/
import requests
from bs4 import BeautifulSoup

headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0'}
link = "https://beijing.anjuke.com/sale/"
r = requests.get(link,headers= headers,timeout=20)

soup = BeautifulSoup(r.text,'html.parser')
house_list = soup.find_all('li',class_="banner-item banner-item-active")

for house in house_list:
    name = house.find('ul',class_='banner_list').a.text.strip()
    price = house.find('span',class_='price-det').text.strip()
    price_area = house.find('span',class_='unit-price').text.strip()

    no_room = house.find('div',class_='details-item').span.text
    area = house.find('div',class_='details-item').contents[3].text
    floor = house.find('div',class_='details-item').contents[5].text
    year = house.find('div',class_='details-item').contents[7].text
    broker = house.find('span',class_='brokername').text
    broker = broker[1:]
    address = house.find('span',class_='comm-address').text.strip()
    address = address.replace('\xa0\xa0\n                 ','  ')
    tag_list = house.find_all('span',class_='item-tags')
    tags = [i.text for i in tag_list]
    print(name, price, price_area, no_room, area, floor, year, broker, address, tags)